<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>websocket</title>
</head>
<body>
<div id="receive">
    <p>empty</p>
</div>

<script>
    var socket = null;
    var wsuri = "ws://localhost:9000/push"

    window.onload = function () {
        socket = new WebSocket(wsuri)

        socket.onopen = function () {
            console.log("connected to " + wsuri)
            socket.send("hello from client")
        }
        socket.onclose = function (e) {
            console.log("connection closed, code=" + e.code)
        }
        socket.onmessage = function (e) {
            p = document.createElement("p")
            p.textContent = e.data
            document.getElementById("receive").appendChild(p)
        }
    }
</script>
</body>
</html>